<style scoped>
  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }

  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }

  .rj-cell {
    display: inline-block;
    font-size: 0;
    padding: 5px 15px;
  }

  .rj-cell.max span {
    font-size: 16px;
    padding-right: 20px;
  }

  .rj-cell label {
    color: #333;
    font-size: 14px;
  }

  .rj-cell span {
    padding-left: 5px;
    font-size: 14px;
    color: #333;
  }

  .rj-cell.note {
    width: 100%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .attachimg {
    /*width: 100%;*/
  }

  .tit label, .tit span {
    font-size: 16px;
  }

  .tit label {
    padding-right: 20px;
  }

  .weui-panel.weui-panel_access {
    padding-bottom: 10px;
  }

  /*.weui-panel__bd:not(.base) {*/
  /*  width: 98%;*/
  /*  padding: 0 1% 2px 1%;*/
  /*}*/

  .rj-cont-tit:not(.base) {
    border-radius: 5px;
  }

  .weui-cell {
    background: #fff;
  }

  .weui-cells__title {
    text-align: left;
    background: #eee;
  }

  .oitem {
    padding: 3px;
    border-bottom: 1px dotted #eee;
  }

  #acts span {
    font-size: 14px;
  }

  .weui-label {
    text-align: left;
  }

  .weui-media-box {
    text-align: left;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .hd .weui-grid.js_grid {
    font-weight: 600;
  }

  .weui-grid.js_grid {
    width: 25%;
    padding: 10px 1px;
  }

  /*.weui-grid.fir {*/
  /*  width: 20%;*/
  /*}*/
  /*.weui-grid.sec {*/
  /*  width: 15%;*/
  /*}*/
  /*.weui-grid.thr {*/
  /*  width: 20%;*/
  /*}*/
  /*.weui-grid.fou {*/
  /*  width: 15%;*/
  /*}*/
  /*.weui-grid.fiv {*/
  /*  width: 15%;*/
  /*}*/
  .weui-grid__label {
    text-overflow: initial;
  }

  /*.view-wrap {*/
  /*  background: #eee;*/
  /*}*/
  .section {
    width: auto;
    margin: 5px;
    border-radius: 5px;
    text-align: left;
    overflow: hidden;
  }
  .itemSection {
    background: #fafafa;
    margin: 3px;
  }
  .itemTit {
    color: #999;
    font-size: 12px;
    margin-left: 15px;
  }
</style>
<template>
  <div class="comon" style="background: #eee;">
    <div
      style="height: 50px; line-height: 50px; background: #fff; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      生产计划详情
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px"/>
      </a>
    </div>
    <!--    主表信息-->
    <div class="weui-form-preview" style="background: #fff;">
      <div class="weui-form-preview__hd">
        <label class="weui-form-preview__label">编号</label>
        <em class="weui-form-preview__value">{{baseInfo.code}}</em>
      </div>
      <div class="weui-form-preview__bd">
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">名称</label>
          <span class="weui-form-preview__value">{{baseInfo.name}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">类型</label>
          <span class="weui-form-preview__value">{{baseInfo.typeName}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">库房</label>
          <span class="weui-form-preview__value">{{baseInfo.strname}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">计划日期</label>
          <span class="weui-form-preview__value">{{baseInfo.planstart}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">状态</label>
          <span class="weui-form-preview__value">{{baseInfo.statusName}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">备注</label>
          <span class="weui-form-preview__value">{{baseInfo.remark}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">操作人</label>
          <span class="weui-form-preview__value">{{baseInfo.createName}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">创建时间</label>
          <span class="weui-form-preview__value">{{baseInfo.createtime}}</span>
        </div>
        <div class="weui-form-preview__item" v-if="baseInfo.files && baseInfo.files.length > 0">
          <label class="weui-form-preview__label">附件</label>
          <a v-for="(item, index) in baseInfo.files" :href="item.url">
            <span class="weui-form-preview__value">{{item.imagename}}</span>
          </a>
        </div>
      </div>
    </div>
    <!--    领料信息-->
    <div v-if="plsCollect != null && plsCollect.length > 0">
      <div class="weui-panel__hd" style="text-align: left;">领料信息</div>
      <div class="weui-panel__bd section" v-if="plssum > 0" style="background: #fff;">
        <div>
          <div class="rj-cell max">
            <label>领料单数量：</label>
            <span>{{plssum}} 个</span>
          </div>
        </div>
      </div>
    </div>
    <div v-if="pls != null && pls.length > 0">
      <div class="weui-panel__hd" style="text-align: left;">领料详情</div>
      <div class="weui-panel__bd section" v-for="(item, index) in pls" style="background: #fff;">
<!--        <div v-for="(item, index) in pls">-->
          <div class="rj-cell max">
            <label>编号：</label>
            <span>{{item.code}}</span>
          </div>
          <div class="rj-cell max">
            <label>状态：</label>
            <span>{{item.statusname}} </span>
          </div>
          <p class="itemTit"> 产品明细 </p>
          <div v-for="(product, index) in item.items" :key="product.guid" style="border-top: 1px solid #ccc;" >
            <div class="itemSection">
              <div class="rj-cell max"  >
                <label> 产品：</label>
                <span>{{product.sthname}}</span>
                <span>{{product.product}} {{product.spename}} </span>
                <span>{{product.weight}}{{product.stockunit}}</span>
              </div>
            </div>
          </div>
<!--        </div>-->
      </div>
    </div>
    <!--    入库信息-->
    <div v-if="hgsum > 0">
      <div class="weui-panel__hd" style="text-align: left;">入库信息</div>
      <div class="weui-panel__bd section" v-if="hgsum > 0" style="background: #fff;">
        <div>
          <div class="rj-cell max">
            <label>入库单数量：</label>
            <span>{{hgsum}} 个</span>
          </div>
        </div>
      </div>
    </div>
    <div v-if="whinforms != null && whinforms.length > 0">
      <div class="weui-panel__hd" style="text-align: left;">入库详请</div>
      <div class="weui-panel__bd section" style="background: #fff;">
        <div v-for="(item, index) in whinforms">
          <div class="rj-cell max">
            <label>编号：</label>
            <span>{{item.code}}</span>
          </div>
          <div class="rj-cell max">
            <label>状态：</label>
            <span>{{item.statusName}} </span>
          </div>
          <div class="rj-cell max">
            <label>领料单编号：</label>
            <span>{{item.pickcode}} </span>
          </div>
          <div class="rj-cell max">
            <label>入库库房：</label>
            <span>{{item.strname}} </span>
          </div>
          <p class="itemTit"> 产品明细 </p>
          <div v-for="(product, index) in item.items" :key="product.guid" style="border-top: 1px solid #ccc;" >
            <div class="itemSection">
              <div class="rj-cell max"  >
                <label> 产品：</label>
                <span>{{product.housename}}</span>
                <span>{{product.product}} {{product.spename}}</span>
                <span>{{product.weight}}{{product.stockunit}}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!--    报废信息-->
    <div v-if="scrapsum > 0">
      <div class="weui-panel__hd" style="text-align: left;">报废信息</div>
      <div class="weui-panel__bd section" v-if="scrapsum > 0" style="background: #fff;">
        <div>
          <div class="rj-cell max">
            <label>报废单数量：</label>
            <span>{{scrapsum}} 个</span>
          </div>
        </div>
      </div>
    </div>
    <div v-if="scraps != null && scraps.length > 0">
      <div class="weui-panel__hd" style="text-align: left;">报废详情</div>
      <div class="weui-panel__bd section" style="background: #fff;">
        <div v-for="(item, index) in scraps">
          <div class="rj-cell max">
            <label>编号：</label>
            <span>{{item.code}}</span>
          </div>
          <div class="rj-cell max">
            <label>状态：</label>
            <span>{{item.statusname}} </span>
          </div>
          <p class="itemTit"> 产品明细 </p>
          <div v-for="(product, index) in item.items" :key="product.guid" style="border-top: 1px solid #ccc;" >
            <div class="itemSection">
              <div class="rj-cell max"  >
                <label> 产品：</label>
                <span>{{product.housename}}</span>
                <span>{{product.product}}</span>
                <span>{{product.weight}} {{product.stockunit}}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!--    退料信息-->
    <div v-if="materialsum > 0">
      <div class="weui-panel__hd" style="text-align: left;">退料信息</div>
      <div class="weui-panel__bd section" v-if="materialsum > 0" style="background: #fff;">
        <div>
          <div class="rj-cell max">
            <label>退料单数量：</label>
            <span>{{materialsum}} 个</span>
          </div>
        </div>
      </div>
    </div>
    <div v-if="materials != null && materials.length > 0">
      <div class="weui-panel__hd" style="text-align: left;">退料详情</div>
      <div class="weui-panel__bd section" style="background: #fff;">
        <div v-for="(item, index) in materials">
          <div class="rj-cell max">
            <label>编号：</label>
            <span>{{item.code}}</span>
          </div>
          <div class="rj-cell max">
            <label>状态：</label>
            <span>{{item.statusname}} </span>
          </div>
          <div class="rj-cell max">
            <label>库房：</label>
            <span>{{item.srName}} </span>
          </div>
          <p class="itemTit"> 产品明细 </p>
          <div v-for="(product, index) in item.items" :key="product.guid" style="border-top: 1px solid #ccc;" >
            <div class="itemSection">
              <div class="rj-cell max"  >
                <label> 产品：</label>
                <span>{{product.shname}}</span>
                <span>{{product.productName}}</span>
                <span>{{product.weight}} {{product.stockunit}}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!--    审批记录-->
<!--    <SalesOperationLogs7 :orderid="id" :srguid="baseInfo.srguid" :departid="baseInfo.departid" :flowid="flowid"></SalesOperationLogs7>-->
    <!--    </div>-->
    <!--  </div>-->
<!--    <CommentBom v-if="isReady" :flowid="flowid" :nodeid="nodeid" :id="id" :srguid="baseInfo.srguid" :departid="baseInfo.departid" :model="baseInfo" :opinion="opinion" :images="images" :refuseflag="refuseflag" :annex="annex" passUrl="/sales/Purchasebill!approval.action" refuseUrl="/sales/Purchasebill!refuse.action" navgateUrl="/purchase2/PurchaseList" ></CommentBom>-->
  </div>
</template>

<script>
  import SalesOperationLogs7 from '../common/SalesOperationLogs7'
  import CommentBom from '@/components/common/CommentBom'

  export default {
    name: 'ViewPlan2',
    data() {
      return {
        flowid: 30,
        openid: localStorage.openid,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
        userid: localStorage.userId,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
        id: '',
        baseInfo: {},
        plsCollect: [],
        pls: [],
        plssum: '',
        hgweight: 0,
        hgsum: 0,
        bhgweight: 0,
        bhgsum:0,
        whinforms: [],
        scrapsum: 0,
        scrapweight:'',
        scraps: [],
        materialsum: '',
        materialweight: '',
        materials: [],
        orderfiles: [],
        isReady: false
      }
    },
    components: {
      SalesOperationLogs7,
      CommentBom
    },
    created() {
      window.addEventListener('setItem', () => {
        this.openid = localStorage.getItem('openid');
        this.userid = localStorage.getItem('userId');
      })
    },
    mounted() {
      this.id = this.$route.query.id;
      this.getbaseInfo(this.id);
    //图片浏览器
      $('.weui-panel').on('click', '.uploaderFiles .attachimg', function () {
        var num = $(this).parent().children().not(".exp").length;
        var imgArr = [];
        for (var i = 0; i < num; i++) {
          imgArr.push($(this).parent().find('.attachimg').eq(i).data('img'));
        }
        var pnum = $(this).parent().find('.exp').length;
        var index = pnum > 0 ? $(this).index() - pnum : $(this).index();
        var pb = $.photoBrowser({
          items: imgArr,
          initIndex: index
        });
        pb.open();
      });

    },
    methods: {
      packUnit: function(unit, currency) {
        return unit != undefined && unit != '' ? currency == 2 ? '美元/' + unit : '元/' + unit : '';
      },
      getbaseInfo: function (id) {
        this.axios({
          method: 'get',
          url: `/prod-api/produce/plan/${id}`,
        }).then(response => {
          if (response.data.code == 200) {
            let data = response.data;
            console.log(data);
            this.baseInfo = data.pp || {};
            this.plsCollect = data.plsCollect != undefined ? data.plsCollect : [];
            this.pls = data.pls != undefined ? data.pls : [];
            this.plssum = data.plssum;
            this.scrapsum = data.scrapsum;
            this.scrapweight = data.scrapweight;
            this.scraps = data.scraps != undefined ? data.scraps : [];
            this.materialsum = data.materialsum;
            this.materialweight = data.materialweight;
            this.materials = data.materials != undefined ? data.materials : [];
            if (data.whinforms != undefined) {
              this.whinforms = data.whinforms != undefined ? data.whinforms : [];
              this.hgweight = data.hgweight;
              this.hgsum = data.hgsum;
            }
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不设置提示
          } else {
            this.toastError('系统错误');
          }
          this.isReady = true;
        });
      },
    }
  }
</script>
